{extend name="layout/base"}

{block name="content"}

<table id="table" lay-filter="filter"></table>
<script type="text/html" id="indexTpl">
  {{d.LAY_TABLE_INDEX+1}}
</script>
<script type="text/html" id="show">
    <a lay-event="edit"><span class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">编辑</span></a>
</script>
<script type="text/html" id="statusTpl">
        {{# switch(d.status) {
        case -1: }}
        <span class="layui-btn layui-btn-danger layui-btn-xs">未开通</span>
        {{# break;
        case 2: }}
        <span class="layui-btn layui-btn-checked layui-btn-xs">开通</span>
        {{# break;
        case 3: }}
        <span class="layui-btn layui-btn layui-btn-xs">打烊</span>
        {{# break;
        case 4: }}
        <span class="layui-btn layui-btn-normal layui-btn-xs">冻结</span>
        {{# break;
        case 5: }}
        <span class="layui-btn layui-btn-normal layui-btn-xs">永久关门</span>
        {{# break;
        default: }}
        未知
        {{# break;
        } }}
</script>
<script src="/static/layui/layui.js" charset="utf-8"></script>
<script>
layui.use(['jquery','table','form','layer'], function(){
    var $ = layui.jquery,
        table = layui.table
        form = layui.form
        layer = layui.layer;
    //渲染
    //商户列表
    var monylist = table.render({
        elem: '#table',
        url: 'lists',
        page: true,
        cols: [[
            {title: '序号', templet: '#indexTpl'},
            {field: 'mername', title: '商户名'},
            {field: 'mobile', title: '手机号'},
            {field: 'open', title: '开门时间'},
            {field: 'close', title: '关门时间'},
            {field: 'discount', title: '折扣'},
            {field: 'status', title: '状态', templet: '#statusTpl'},
            {field: 'retime', title: '注册时间',templet:"<div>{{layui.util.toDateString(d.retime*1000,'yyyy-MM-dd HH:mm:ss')}}</div>"},
            {field: 'retime', title: '详情',templet:'#show'}
        ]],
    });
    table.on('tool(filter)', function(obj){ 
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event;       
        if(layEvent == 'edit'){ //编辑
            layer.open({
                type: 2,
                title: '编辑',
                skin: 'layui-layer-rim', 
                content: '/manager/merchant/show/merid/?merid='+data.merid,
                area: ['100%','100%']
            }); 
        }
    });
});



// function down(ids)
// {
//     var xmlResquest = new XMLHttpRequest();
// //  发起请求
//     xmlResquest.open("POST", "create_zip?ids=" + ids, true);
// // 设置请求头类型
//     xmlResquest.setRequestHeader("Content-type", "application/json");
//     xmlResquest.setRequestHeader("ids", ids);
//     xmlResquest.responseType = "blob";
// //  返回
//     xmlResquest.onload = function (data) {
//         //alert(oEvent);
//         var content = xmlResquest.response;
//         // 组装a标签
//         var elink = document.createElement("a");
//         var f_name = xmlResquest.getResponseHeader('Content-Disposition').split(";")[1].split("filename=")[1];
//         //设置文件下载路径
//         elink.download = f_name.slice(1,-1);
//         elink.style.display = "none";
//         var blob = new Blob([content]);
//
//         //解决下载不存在文件的问题，根据blob大小判断
//         if (blob.size == 0) {
//             layer.msg('服务器没找到此文件，请联系管理员!');
//         } else {
//             elink.href = URL.createObjectURL(blob);
//             document.body.appendChild(elink);
//             elink.click();
//             document.body.removeChild(elink);
//         }
//     };
//     xmlResquest.send();
// }
</script>
{/block}
